home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / packet / p_tapr / tnchst / mthdrive.asm < prev    next >
Assembly Source File  |  1992-03-16  |  19KB  |  975 lines

  1.     PAGE    60,132
  2.     TITLE    MTDRIVER
  3. ;
  4. ; MTHDRIVER
  5. ;
  6. ; Derived from AA4RE's COMBIOS.ASM, heavily modifed by
  7. ; WA7MXZ, WA7MBL, W0RLI, and N2WX
  8. ;
  9. ;
  10. ;
  11. _DATA SEGMENT WORD PUBLIC 'DATA'
  12. _DATA    ENDS
  13.  
  14. _TEXT SEGMENT BYTE PUBLIC 'CODE'
  15.       ASSUME CS: _TEXT
  16.       ASSUME DS: nothing
  17.       ASSUME ES: nothing
  18.       ASSUME SS: nothing
  19.  
  20. ; Program _COM_START and buffer declares
  21.  
  22.     ORG    0
  23.  
  24. ; Area where things are declared
  25.  
  26.  include MTCONST.ASM
  27.  
  28. COMPORT    EQU    0
  29.  
  30. dummy:                      ; Dummy labels to provide a structure
  31.  
  32. i_buf     DB     buffer_size dup(?)  ; Buffer (1 per com card)
  33. i_buf_e:                 ; End of buffer
  34. comnumber DB      ?              ; Comm number - 1
  35. flags      DB      ?              ; Flag byte
  36. last_rs   DB      ?              ; Last receive status
  37. hiv      DB      ?              ; Hardware interrupt vector
  38. int_mask  DB      ?              ; Mask for 8259
  39. baseaddr  DW      ?              ; Base port address
  40. i_count     DW        ?            ; # of chars in buffer
  41. i_buf_in DW     ?             ; Buffer in pointer
  42. i_buf_out DW     ?             ; Buffer out pointer
  43. dummy_end:
  44.  
  45.       ORG      dummy           ; Back up over this
  46.  
  47. ; These are the things to work with
  48.  
  49.  
  50.  IF COMPORT - 1        ; COM1 defined below
  51.       DB      buffer_size dup(?)  ; Buffer (1 per com card)
  52.       DB      0              ; Com number
  53.       DB      0              ; Flags
  54.       DB      0              ; Last receive status
  55.       DB      0CH              ; Hardware interrupt vector
  56.       DB      0EFH              ; Mask
  57.       DW      03F8H           ; Base port address
  58.       DW      0              ; # of chars in buffer
  59.       DW      ?              ; Buffer in pointer
  60.       DW      ?              ; Buffer out pointer
  61.  ELSE        ; else COM2
  62.       DB      buffer_size dup(?)  ; Buffer (1 per com card)
  63.       DB      1              ; Com number
  64.       DB      0              ; Flags
  65.       DB      0              ; Last receive status
  66.       DB      0bH              ; Hardware interrupt vector
  67.       DB      0F7H              ; Mask
  68.       DW      02F8H           ; Base port address
  69.       DW      0              ; # of chars in buffer
  70.       DW      ?              ; Buffer in pointer
  71.       DW      ?              ; Buffer out pointer
  72.   ENDIF
  73.  
  74. comend:                   ; Marker for last com port
  75.  
  76. ; Static variables
  77.  
  78. old_bios_vector   DW  ?        ; Save previous interrupt vector
  79.           DW  ?
  80.  
  81.  
  82. old_hdwr_vec    DW ?
  83.         DW ?
  84.  
  85. old_ier        DB    ?
  86.  
  87. old_pic_msk    DB    ?
  88.  
  89. divisor_table LABEL WORD
  90.     DW    1047            ; 110
  91.     DW    6            ; 19200
  92.     DW    384            ; 300
  93.     DW    192            ; 600
  94.     DW    96            ; 1200
  95.     DW    48            ; 2400
  96.     DW    24            ; 4800
  97.     DW    12            ; 9600
  98.  
  99.  
  100. ; Our BIOS handler
  101.  
  102. rsint:
  103.  
  104.     ASSUME DS: NOTHING       ; Don't use DS
  105.     ASSUME ES: NOTHING       ; Don't use ES
  106.     ASSUME SS: NOTHING       ; Don't use SS
  107.  
  108. ; Not disabled please
  109.  
  110.     STI
  111.  
  112. ; See if this is our vector?
  113.  
  114.     PUSH    BP            ; Save BP over our loop
  115.     XOR    BP,BP
  116.     CMP    DL,CS:comnumber[BP] ; Is this our port?
  117.     JE    rsint_ours        ; Yes...
  118.  
  119. ; Not us.. Pop things out and call regular handler
  120.  
  121.     POP    BP            ; Pop BP
  122.     JMP    CS:DWORD PTR old_bios_vector
  123.  
  124. ; BP now contains the pointer to the com block...  See what
  125. ; the user has requested and we may or may not do it.......
  126.  
  127. rsint_ours:
  128.  
  129.     PUSH    DX            ; We need the DX register
  130.     PUSH    CX            ; We need the CX register
  131.     PUSH    BX            ; We need the BX register
  132.  
  133.     MOV    CX,baseaddr[BP]     ; Get base address for chip
  134.  
  135.     OR    AH,AH            ; Initialize
  136.     JE    rsint_init        ; Yes...
  137.  
  138.     DEC    AH            ; 1 = Send character
  139.     JZ    rsint_send
  140.  
  141.     DEC    AH            ; 2 = Receive character
  142.     JZ    rsint_recv_jmp
  143.  
  144.     DEC    AH            ; 3 = Status request
  145.     JZ    rsint_status_jmp
  146.  
  147.     DEC    AH            ; 4 = Inquiry
  148.     JZ    rsint_inquiry_jmp
  149.  
  150.     jmp    rsint_exit        ;       Nope..
  151.  
  152. rsint_recv_jmp:
  153.     JMP    rsint_recv
  154. rsint_status_jmp:
  155.     JMP    rsint_status
  156. rsint_inquiry_jmp:
  157.     JMP    rsint_inquiry
  158.  
  159. ; Interrupt exit
  160.  
  161. rsint_exit:
  162.  
  163.     POP    BX            ; Restore registers
  164.     POP    CX
  165.     POP    DX
  166.     POP    BP
  167.     IRET                ;       and leave
  168.  
  169. ; Init..
  170.  
  171. rsint_init:
  172.  
  173.  
  174.     MOV    AH,AL            ; Save the parms for later
  175.  
  176.     MOV    BL,AH            ; Look up the baud rate
  177.     MOV    CL,4            ; parameter
  178.     ROL    BL,CL
  179.     AND    BX,0EH
  180.     MOV    BX,divisor_table[BX]
  181.  
  182.     MOV    CX,baseaddr[BP]     ; Get base address for chip
  183.     MOV    DX,CX            ; Address of LCR
  184.     ADD    DX,lcr_8250
  185.     MOV    AL,10000000B        ; Enable access to divisor
  186.     OUT    DX,AL
  187.  
  188.     MOV    DX,CX            ; Address of lower divisior half
  189.     ADD    DX,dll_8250
  190.     MOV    AL,BL            ; Put lower half
  191.     OUT    DX,AL
  192.  
  193.     MOV    DX,CX            ; Address of upper divisior half
  194.     ADD    DX,dlm_8250
  195.     MOV    AL,BH            ; Put upper half
  196.     OUT    DX,AL
  197.  
  198.     MOV    AL,AH            ; Get parms back
  199.     AND    AL,01FH         ; Throw away baud rate
  200.     MOV    DX,CX            ; Address of LCR
  201.     ADD    DX,lcr_8250
  202.     OUT    DX,AL            ; Output the parms
  203.  
  204. ; Turn on the port
  205.  
  206.     MOV    DX,CX          ; Compute port address for the MCR
  207.     ADD    DX,mcr_8250
  208.     mov    AL,00001011B      ; Raise DTR, RTS  & OUT2
  209.     out    dx,al          ; OUT2 turns on interrupts
  210.  
  211.     JMP    rsint_status        ; Now just status please
  212.  
  213. ; Send a character
  214.  
  215. rsint_send:
  216.  
  217.     MOV    AH,AL            ; Save the character to send
  218.  
  219. rsint_send_loop:            ; Loop here until we can send
  220.  
  221. ;; below taken out; ignore cts
  222. ;; RESTORE 29 DEC 90 TO WORK WITH UPLOAD/THRUPUT STUFF
  223.     MOV    DX,CX            ; Compute port address for the MSR
  224.     ADD    DX,msr_8250        ;       and then
  225.     IN    AL,DX            ;       get it into AX
  226.     AND    AL,10H            ; CTS
  227.     jz    rsint_send_loop
  228.  
  229.     MOV    DX,CX            ; Compute port address for the LSR
  230.     ADD    DX,lsr_8250        ;       and then
  231.     IN    AL,DX            ;       get itinto AX
  232.     and    AL,20H            ; THR empty?
  233.     JZ    rsint_send_loop     ;       No.. Loop back
  234.  
  235.     MOV    AL,AH            ; Get ready to out character
  236.  
  237.     MOV    DX,CX            ; Compute port address for the THR
  238.     ADD    DX,thr_8250        ;       and then
  239.     OUT    DX,AL            ;       out the character
  240.  
  241.     JMP    rsint_status        ; Do a status
  242.  
  243. ; Receive a character
  244.  
  245. rsint_recv:
  246.  
  247.     MOV    BX,i_buf_out[BP]   ; Get buffer output pointer
  248.  
  249. rsint_recv_loop:
  250.  
  251.     CMP    i_count[BP],0          ; See in anything in buffer
  252.     JE    rsint_recv_loop     ; Wait for it
  253.  
  254. rsint_get_char:
  255.     MOV    AL,CS:[BX]        ; Get character from buffer
  256.     PUSH    AX            ; Save char
  257.     INC    BX            ; Bump pointer
  258.     DEC    i_count[BP]          ; Dec char count
  259.     MOV    DX,OFFSET i_buf_e  ; Compute end of buffer
  260.     ADD    DX,BP
  261.     CMP    BX,DX            ; Have we wrapped the buffer?
  262.     JL    test_handshake        ;       No.. All done
  263.     MOV    BX,OFFSET i_buf    ;      Yes.. Reset pointer
  264.     ADD    BX,BP
  265. test_handshake:
  266.     cmp    i_count[BP],80H
  267.     jnb    test_full
  268.     mov    ah,flags[BP]
  269.     test    ah,1            ; Did we RTS off?
  270.     jz    test_full        ; No, so don't RTS on
  271. roll_hands:
  272.     mov    DX,CX
  273.     add    DX,mcr_8250
  274.     in    AL,DX
  275.     or    AL,00001011B        ; Raise DTR, RTS  & OUT2
  276.     out    DX,AL
  277.     and    AH,0FEH         ; Remember RTS is on
  278.     mov    flags[BP],AH
  279.  
  280. test_full:
  281.     POP    AX            ; Restore Char
  282.  
  283.     MOV    i_buf_out[BP],BX   ; Save pointer
  284.     MOV    AH,last_rs[BP]        ; Get last LSR from receive
  285.     AND    AH,0FEH         ; Remove data ready bit
  286.     CMP    i_count[BP],0          ; Anything left in buffer?
  287.     JE    short_exit        ;       Nope so leave
  288.     OR    AH,1            ; Turn on data ready
  289. short_exit:
  290.     JMP    rsint_exit        ;       and go leave
  291.  
  292. ; Status..
  293.  
  294. rsint_status:
  295.  
  296.     MOV    DX,CX            ; Compute port address for the LSR
  297.     ADD    DX,lsr_8250        ;       and then
  298.     IN    AL,DX            ;       get it
  299.  
  300.     AND    AL,0FEH         ; Remove data ready bit
  301.  
  302.     CMP    i_count[BP],0          ; Anything left in buffer?
  303.     JE    rsint_status_nodr   ;       Nope so leave
  304.     OR    AL,1            ; Turn on data ready
  305. rsint_status_nodr:
  306.     MOV    AH,AL            ; Save LSR
  307.  
  308.     MOV    DX,CX            ; Compute port address for the MSR
  309.     ADD    DX,msr_8250        ;       and then
  310.     IN    AL,DX            ;       get it
  311.  
  312.     JMP    rsint_exit        ; All done
  313.  
  314. ; Inquiry
  315. ; (Return 7388H in AX - Just an identification scheme to tell
  316. ;  if this silly driver has been loaded)
  317.  
  318. rsint_inquiry:
  319.  
  320.     MOV    AX,07388H
  321.     JMP    rsint_exit        ;       and go leave
  322.  
  323. ; 8250 interrupt handler
  324.  
  325. serint_8250:
  326.  
  327.     PUSH    BP
  328.     PUSH    DX
  329.     PUSH    AX
  330.     PUSH    CX            ; Save some registers
  331.     PUSH    DI
  332.     xor    bp,bp
  333.  
  334.     MOV    CX,CS:baseaddr[BP]     ; Get base address for chip
  335.  
  336.     MOV    DX,CX            ; Get the IIR
  337.     ADD    DX,iir_8250
  338.     IN    AL,DX
  339.  
  340.     TEST    AL,1            ; Interrupt pending?
  341.     JZ    service
  342.     JMP    serint_8250_exit    ;      No leave...
  343.  
  344. service:
  345.     MOV    DX,CX            ; Get the LSR
  346.     ADD    DX,lsr_8250
  347.     IN    AL,DX
  348.     MOV    last_rs[BP],AL        ; And tuck it away
  349.  
  350.     MOV    DX,CX            ; Get the RBR
  351.     ADD    DX,rbr_8250
  352.     IN    AL,DX
  353.     MOV    DI,i_buf_in[BP]    ; Get the buffer pointer
  354.     MOV    CS:[DI],AL        ; Save the character
  355.     INC    DI            ; Bump pointer and handle wrap
  356.     MOV    AX,OFFSET i_buf_e
  357.     ADD    AX,BP
  358.     CMP    DI,AX
  359.     JL    nowrap
  360.     MOV    DI,OFFSET i_buf
  361.     ADD    DI,BP
  362.  
  363. nowrap:
  364.  
  365.     cmp    i_count[BP],buffer_full
  366.     jb     hand_done
  367.     mov    DX,CX
  368.     add    DX,mcr_8250
  369.     in     al,DX
  370.     and    AL,11111100B        ; Drop DTR & RTS
  371.     out    DX,AL
  372.     mov    ah,flags[BP]
  373.     or     AH,1            ; Remember RTS is off
  374.     mov    flags[BP],AH
  375.  
  376. hand_done:
  377.  
  378.     CMP    DI,i_buf_out[BP]   ; Overflow of buffer?
  379.     JNE    noover
  380.     OR    last_rs[BP],2        ; Overrun indicate
  381.     JMP    SHORT serint_8250_exit ;  Don't save the updated pointer
  382. noover:
  383.     MOV    i_buf_in[BP],DI    ; Save the updated pointer
  384.     inc    i_count[BP]          ; inc char count
  385.  
  386. serint_8250_exit:
  387.  
  388.     MOV    AL,20H            ; Tell 8259 we are done
  389.     OUT    pic_cmd_port,AL
  390.     POP    DI            ; Restore registers
  391.     POP    CX
  392.     POP    AX
  393.     POP    DX
  394.     POP    BP
  395.  
  396.     IRET                ; Exit
  397.  
  398. program_end:
  399.  
  400. ; Main line to initialize.
  401.  
  402.       ASSUME DS: _TEXT
  403. ; Constants only needed by initialization
  404.  
  405. P3F8    DB    0    ;1 IF CARD AT 3F8
  406. P2F8    DB    0    ;1 IF CARD AT 2F8
  407.  
  408.  
  409. ; INITIALIZE ROUTINE
  410.     PUBLIC    _COM_START
  411.  
  412. _COM_START PROC NEAR
  413.     PUSH    BP
  414.     PUSH    AX
  415.     PUSH    BX
  416.     PUSH    CX
  417.     PUSH    DX
  418.     PUSH    DS            ; save data seg
  419.  
  420.     MOV    AX,CS              ; Point DS in the right place
  421.     MOV    DS,AX
  422. ;CALL    SINON    ;PRINT SIGN ON
  423.  
  424. ;    MOV    DX,00    ;Check to see if support already loaded
  425. ;    MOV    AH,04
  426. ;    INT    14H
  427. ;    CMP    AX,07388H
  428. ;    JZ    EXIT    ;Must be loaded
  429.  
  430.     CALL    CNFIG    ;CHECK CONFIGURATION
  431.     OR    AX,AX
  432.     JNZ    EREXIT    ;JMP IF ERRORS
  433.  
  434.     CLI
  435.     CALL    init_vectors    ;SET INTERRUPT VECTORS
  436.     STI
  437.     POP    DS
  438.     POP    DX
  439.     POP    CX
  440.     POP    BX
  441.     POP    AX
  442.     POP    BP
  443.     ret
  444. ;;    MOV    AL,0        ;set exit code
  445. ;    MOV    DX,OFFSET program_end
  446. ;    MOV    CL,4
  447. ;    SHR    DX,CL
  448. ;    INC    DX
  449. ;    MOV    AH,31H
  450. ;    INT    21H        ; Terminate but stay resident
  451.  
  452. EREXIT:
  453.     LEA    DX,LOADERR
  454.     MOV    AH,9
  455.     INT    21H
  456.     POP    DS
  457.     POP    DX
  458.     POP    CX
  459.     POP    BX
  460.     POP    AX
  461.     POP    BP
  462.     ret
  463. ;MOV    AL,1        ;set exit code = Error
  464. ;    MOV    AH,4CH
  465. ;    INT    21H        ; Terminate and return
  466.  
  467. LOADERR:
  468.     DB    CR,LF,'COULDNT INSTALL, NO COM DRIVER HERE NOW',CR,LF,'$'
  469.  
  470. EXIT:
  471.     POP    DS
  472.     POP    DX
  473.     POP    CX
  474.     POP    BX
  475.     POP    AX
  476.     POP    BP
  477.     ret
  478. _COM_START ENDP
  479. ;---------
  480. CNFIG:
  481. ; call to FNDPT, and two lines at CNF1 removed to prevent screw
  482. ; up with non-compat machines?   done oct 27 88
  483. ;    CALL    FNDPT        ;Find Ports
  484. ;  below 4 ';' inserted 1  april
  485. ;    CMP    P3F8,1
  486. ;    JNE    CNF1
  487.  
  488. ;CNF1:    CMP    P2F8,1
  489. ;    JE    CNF3
  490.     JMP    CNF3    ; indicate OK
  491.  
  492. ;CNF2:    CMP    P3F8,1
  493. ;    JE    CNF3
  494.  
  495. CNFERR: MOV    AX,0FFFFH    ;Set Error
  496.     RET
  497.  
  498. CNF3:    SUB    AX,AX
  499.     RET
  500.  
  501. ;------------
  502.  
  503. FNDPT:    MOV    DX,03F8H
  504.     CALL    CKPORT
  505.     CMP    BP,0
  506.     JZ    PT2
  507.  
  508.     INC    P3F8
  509.  
  510. PT2:    MOV    DX,02F8H
  511.     CALL    CKPORT
  512.     CMP    BP,0
  513.     JZ    PT3
  514.  
  515.     INC    P2F8
  516.  
  517. PT3:    RET
  518.  
  519.  
  520. ; Check for valid Port
  521. ; Enter with DX containing Port address
  522. ; Exit with BP=Port address if port found  BP=0 if not found
  523.  
  524.  
  525. CKPORT: MOV    BP,DX        ;For return
  526.     MOV    CL,DL        ;Keep DL Handy
  527.  
  528.     ADD    DX,3
  529.     IN    AL,DX        ;Save old LCR in CH
  530.     MOV    CH,AL
  531.  
  532.     MOV    AL,80H        ;Address Divisor Latch
  533.     OUT    DX,AL
  534.     CALL    WAIT
  535.  
  536.     MOV    DL,CL
  537.     IN    AL,DX
  538.     MOV    AH,AL        ;Save old Divisor
  539.     CALL    WAIT
  540.  
  541.     INC    DX
  542.     IN    AL,DX        ;Save old Divisor
  543.     MOV    BX,AX
  544.     CALL    WAIT
  545.  
  546.     MOV    DL,CL
  547.     MOV    AL,55H        ;OUTPUT 55
  548.     OUT    DX,AL
  549.     CALL    WAIT
  550.  
  551.     INC    DX
  552.     MOV    AL,0AAH
  553.     OUT    DX,AL        ;OUTPUT AA
  554.     CALL    WAIT
  555.  
  556.     MOV    DL,CL
  557.     IN    AL,DX        ;Read New Divisor
  558.     MOV    AH,AL
  559.     CALL    WAIT
  560.  
  561.     INC    DX
  562.     IN    AL,DX
  563.     CMP    AX,55AAH    ;DO THEY MATCH?
  564.     JZ    Match
  565.  
  566.     XOR    BP,BP        ;Zero - no match
  567.  
  568. Match:    MOV    DL,CL
  569.     MOV    AL,BH        ;Restore old Divisor
  570.     OUT    DX,AL
  571.     CALL    WAIT
  572.  
  573.     INC    DX
  574.     MOV    AL,BL
  575.     OUT    DX,AL
  576.     CALL    WAIT
  577.  
  578.     INC    DX
  579.     INC    DX        ;and old LCR
  580.     MOV    AL,CH
  581.     OUT    DX,AL
  582.     CALL    WAIT
  583.  
  584. WAIT:    NOP
  585.     RET
  586.  
  587. ; Now snatch the BIOS comm vector  (Int 14)
  588.  
  589. init_vectors:
  590.  
  591.     MOV    AL,14H
  592.     MOV    AH,35H
  593.     INT    21H
  594.     MOV    old_bios_vector,BX     ;      save old vector
  595.     MOV    old_bios_vector+2,ES
  596.  
  597.     XOR    bp,bp
  598.     MOV    AL,hiv[bp]         ; HG hang onto hdwr vec too
  599. ;    MOV    AL,CS:hiv
  600.        MOV    AH,35H
  601.     INT    21H            ; GET OLD HDWR VEC
  602.     MOV    old_hdwr_vec,BX
  603.     MOV    old_hdwr_vec+2,ES
  604. ;
  605.     MOV    DX,OFFSET rsint     ; Replace with our vector
  606.     MOV    AL,14H
  607.     MOV    AH,25H
  608.     INT    21H
  609.  
  610. ; Set the hardware interrupt vector
  611.  
  612.     XOR    bp,bp               ; Get a zero
  613.     MOV    DX,OFFSET serint_8250  ; Get our address
  614.     MOV    AL,hiv[BP]
  615. ;    MOV    AL,CS:hiv
  616.     MOV    AH,25H
  617.     INT    21H
  618.  
  619. ; Initialize the buffer ring pointers
  620.  
  621.     MOV    AX,OFFSET i_buf  ; Get _COM_START of buffer address
  622.     ADD    AX,BP          ; include our offset
  623.     MOV    i_buf_in[BP],AX  ; Put in the buffer pointers
  624.     MOV    i_buf_out[BP],AX ; Put in the buffer pointers
  625.  
  626. ; Set the interrupt registers in the UART and clean things up
  627.  
  628.     CLI              ; Disable interrupts
  629.  
  630.     IN    AL,pic_mask_port  ; Set up 8259 interupt controller
  631.     MOV    old_pic_msk , AL    ; hang onto it HG
  632.  
  633.     AND    AL,int_mask[BP]   ; Enable the interrupts for this device
  634.     OUT    pic_mask_port,AL
  635.  
  636.     MOV    CX,baseaddr[BP]     ; Get base address for chip
  637.  
  638.     MOV    DX,CX          ; Compute port address for the IER
  639.     ADD    DX,ier_8250
  640.     IN    AL,DX          ; current int status
  641.     MOV    old_ier , AL
  642.  
  643.     MOV    AL,1          ; Enable data interrupt only
  644.     OUT    DX,AL
  645.  
  646.     MOV    DX,CX          ; Compute port address for the RBR
  647.     ADD    DX,rbr_8250
  648.     IN    AL,DX          ; Read the input buffer and throw it away
  649.  
  650. ; Enable interrupts
  651.  
  652.     STI               ; Enable CPU to receive interupts
  653.     RET
  654.  
  655.     PUBLIC    _REMOVE_VECTOR
  656. _REMOVE_VECTOR PROC NEAR
  657.     assume DS: nothing
  658. ;
  659.     PUSH    BP
  660.     PUSH    DS
  661. ;
  662. ;
  663.     CLI
  664. ;
  665.     MOV    DX,CS:old_bios_vector     ;      restore old vector
  666.     MOV    AX,CS:old_bios_vector+2
  667.     MOV    DS,AX
  668. ;
  669.     MOV    AL,14H
  670.     MOV    AH,25H
  671.     INT    21H
  672. ;
  673.     XOR    bp,bp
  674. ;
  675. ;
  676.     MOV    DX,CS:old_hdwr_vec    ; HG replace old hdwr vec
  677.     MOV    AX,CS:old_hdwr_vec+2
  678.     MOV    DS,AX
  679.     MOV    AL,hiv[bp]
  680. ;    MOV    AL,CS:hiv
  681.     MOV    AH,25H
  682.     INT    21H
  683. ;
  684.     MOV    AL,old_pic_msk
  685.     OUT    pic_mask_port , AL
  686. ;
  687. ;    MOV    AL,old_ier
  688.     mov    al,0            ; disable ints on entire chip
  689.     MOV    DX,baseaddr[BP]
  690.     ADD    DX,ier_8250
  691.     OUT    DX,AL
  692. ;
  693.     STI
  694. ;
  695.     POP    DS
  696.     POP    BP
  697.     RET
  698.  
  699. _REMOVE_VECTOR    ENDP
  700.  
  701.   if 1
  702.     PUBLIC    _GETAUX
  703. _GETAUX    PROC NEAR
  704.     MOV    AH,2        ; GET CHAR
  705.     MOV    DX,COMPORT
  706.     INT    14H
  707.     XOR    AH,AH        ; ZAP AH
  708.     RET
  709. _GETAUX    ENDP
  710.  
  711.     PUBLIC    _AUXAVAIL
  712. _AUXAVAIL PROC NEAR
  713.     MOV    AH,3        ; STAT
  714.     MOV    DX,COMPORT
  715.     INT    14H
  716.     AND    AX,0100H    ; MASK FOR BIT 0 OF AH, DATA READY
  717.     RET
  718. _AUXAVAIL ENDP
  719.  
  720. ;    PUBLIC    _AUXRDY
  721. _AUXRDY    PROC    NEAR
  722.     MOV    AH,3        ; STAT
  723.     MOV    DX,COMPORT
  724.     INT    14H
  725.     AND    AX,0010H    ; RETURN CTS STATE
  726.     RET
  727. _AUXRDY    ENDP
  728.  
  729.     PUBLIC    _PUTAUX
  730. _PUTAUX    PROC    NEAR
  731.     PUSH    BP
  732.     MOV    BP,SP
  733. ;
  734.     MOV    AH,1    ; CHAR OUT
  735.     MOV    DX,COMPORT    ; COM2
  736.     MOV    AL,[BP+4]    ; CHAR TO OUTPUT
  737.     INT    14H
  738.     POP    BP
  739.     RET
  740. _PUTAUX ENDP
  741. ;
  742. ;
  743. BUFSIZE    EQU    2048    ; SIZE OF BUFFER TO USE FOR READING UPLOAD FILE
  744. ;
  745. _DATA    SEGMENT    'DATA'
  746.  
  747. UPHANDLE DW    ?     ; UPLOAD FILE HANDLE HERE
  748. RBUF     DB    BUFSIZE DUP (?)
  749.  
  750. _DATA            ENDS
  751. ;
  752. ;
  753. ;
  754.     PUBLIC    _FILETOTNC
  755. _FILETOTNC    PROC    NEAR        ; UPLOAD A FILE TO THE COM PORT
  756.  
  757.    ASSUME DS:_DATA
  758.  
  759.     PUSH    BP
  760.     MOV    BP,SP
  761. ;
  762.     MOV    DX,[BP+4]    ; NEAR STRING POINTER TO FILE NAME
  763.     MOV    AX,3D00H    ; OPEN FILE FOR READ ONLY
  764.     INT    21H        ; DOS CALL
  765. ;
  766.     JC    ERR        ;   BRIF ERROR OPENING
  767. ;
  768.     MOV    UPHANDLE,AX    ; SAVE FILE HANDLE
  769. ;
  770. READBLK:
  771.     LEA    DX,RBUF        ; POINTER TO AREA TO READ TO
  772.     MOV    CX,BUFSIZE    ; READ BUFSIZE CHARS AT A TIME
  773.     MOV    BX,UPHANDLE
  774.     MOV    AH,63        ; DOS CALL 63 READ
  775.     INT    21H
  776.     JC    CLERR        ; BRIF ERROR READING
  777.     TEST    AX,AX        ; 0 MEANS READ PAST EOF AND WE'RE DONE
  778.     JZ    OKBYE
  779. ;
  780.     LEA    DI,RBUF
  781. ; ELSE AX HAS COUNT OF THIS BLOCK READ, DX POINTS TO BEGINNING OF BLOCK
  782. TOCOMLP:
  783.     PUSH    AX        ; SAVE COUNT
  784.     PUSH    DI        ; AND PTR TO BLOCK
  785. ;
  786.         MOV    AL,BYTE PTR [DI]    ; GET A CHAR FROM THE BUFFER
  787.     AND    AL,07FH
  788.     CMP    AL,1AH
  789.     JE    OKBYEPOP    ;   BRIF ^z ENCOUNTERED = DONE
  790.  IF 1    ; IF OUTPUT TO CONSOLE not DESIRED
  791.     CMP    AL,0AH        ; FILTER LINEFEEDS
  792. ;    JE    IGNORE
  793. ;
  794.     PUSH    AX
  795.     MOV    AH,1        ; CHARACTER OUT
  796.     MOV    DX,COMPORT
  797.     INT    14H        ; COM DRIVER CHARACTER OUT CMD
  798.     POP    AX
  799.  ELSE  ; else out to console   ECHO to console too
  800.     MOV    AH,14        ; WRITE TTY CHAR
  801.     INT    10H        ; VIDEO ROM BIOS CALL
  802.  ENDIF
  803. ;
  804. IGNORE:
  805.     CALL    SHORT TSTKBD    ; CHECK FOR INTERRUPT, RETURN CY SET IF
  806.                 ; ABORT
  807.     POP    DI
  808.     POP    AX
  809. ;
  810.     JC    OKBYE        ; BRIF ABORT RECEIVED ON KEYBOARD
  811. ;
  812. ;
  813.     INC    DI        ; BUMP PTR TO NEXT CHAR
  814.     DEC    AX        ; BUMP DOWN
  815.     JNZ    SHORT TOCOMLP        ; IF MORE TO SEND THEN GO FOR IT
  816.     JMP    SHORT READBLK    ; DO NEXT BLOCK
  817. OKBYEPOP:
  818.     ADD    SP,4        ; FIXUP STACK ON ^z DETECTION AND
  819.                 ; FALL THROUGH TO BYE
  820. ;
  821. OKBYE:
  822.     XOR    AX,AX        ; 0 MEANS OKAY
  823. CLERR:
  824.     PUSH    AX
  825.         MOV    BX,UPHANDLE    ; CLOSE THE OPEN HANDLE
  826.     MOV    AH,62        ; CLOSE
  827.     INT    21H
  828.     POP    AX
  829. ERR:                ; ERR RETURNS WITH ERR CODE
  830.     POP    BP
  831.     RET
  832. _FILETOTNC    ENDP
  833.  
  834.  
  835. TSTKBD     PROC    NEAR
  836.     MOV    AH,1        ; CALL KBD READY SERVICE?
  837.     INT    16H
  838.     JNZ    SHORT GETCH    ;  BRIF IT WAS READY (NOT Z)
  839.     CLC            ; INDICATE NOTHING
  840.     RET            ; BACK TO CALLER
  841. GETCH:
  842.     STC            ; ELSE SET IT SO  now force abort all time
  843. NOTESC:    RET            ; AND BACK TO CALLER
  844. ;
  845. TSTKBD    ENDP
  846.  
  847. ; for test - "ping" RTS and DTR lines 
  848.     PUBLIC    _PING_HDWR
  849. _PING_HDWR    PROC
  850.     MOV    DX,3F8H          ; Compute port address for the MCR
  851.     ADD    DX,mcr_8250
  852.     mov    AL,00001000B      ; Lower DTR, RTS, OUT2
  853.     out    dx,al          ; OUT2 turns on interrupts
  854.     mov    AL,00001011B      ; Raise DTR, RTS  & OUT2
  855.     out    dx,al          ; OUT2 turns on interrupts
  856.     RET
  857. _PING_HDWR    ENDP
  858.  
  859.  
  860.  
  861. ;Hercules stuff from herc manual
  862. index    equ    03b4h
  863. cntrl    equ    03b8h
  864. confsw    equ    03bfh
  865. scrn_on    equ    8
  866. grph    equ    2
  867. txt    equ    020h
  868.  
  869.  
  870. gtable:    db    35h,2dh,2eh,07h
  871.     db    5bh,02h,57h,57h
  872.     db    02,03,00,00
  873.  
  874. ttable:    db    61h,50h,52h,0fh
  875.     db    19h,06h,19h,19h
  876.     db    02h,0dh,0bh,0ch
  877.  
  878.  
  879.     PUBLIC    _TMODE,_GMODE
  880.     assume    cs:_TEXT, ds:_TEXT
  881.  
  882. _GMODE    proc    near
  883.  
  884.     call    enabgr
  885.     push    es
  886.     push    ds
  887. ;mov    ax,xdata
  888. ;mov    ds,ax
  889.     mov    ax,cs
  890.     mov    ds,ax
  891.     mov    al,grph
  892.     lea    si,gtable
  893.     mov    bx,0
  894.     mov    cx,4000h
  895.     call    setmd
  896.     pop    ds
  897.     pop    es
  898.     ret
  899. _GMODE    endp
  900.  
  901. _TMODE    proc    near
  902.     assume    cs:_TEXT
  903.  
  904.     call    enabgr
  905.     push    es
  906.     push    ds
  907. ;mov    ax,xdata
  908. ;mov    ds,ax
  909.     mov    ax,cs
  910.     mov    ds,ax
  911.     mov    al,txt
  912.     lea    si,ttable
  913.     mov    bx,720h
  914.     mov    cx,2000H        ;shows 2000 (no H) in manual
  915.     call    setmd
  916.  
  917.     pop    ds
  918.     pop    es
  919.     ret
  920. _TMODE    endp
  921.  
  922. enabgr    proc    near            ; merely init to accept graphs
  923.     mov    dx,confsw        ; to software switch
  924.     mov    al,3            ; allow pg 0 graph
  925.     out    dx,al
  926.     ret
  927. enabgr    endp
  928.  
  929. setmd    proc    near
  930.     assume    ds:nothing, cs:_TEXT
  931.     push    ds
  932.     push    es
  933.     push    ax
  934.     push    bx
  935.     push    cx
  936.     mov    dx,cntrl
  937.     out    dx,al
  938.     mov    ax,ds
  939.     mov    es,ax
  940.     mov    dx,index
  941.     mov    cx,12
  942.     xor    ah,ah
  943. parms:
  944.     mov    al,ah
  945.     out    dx,al
  946.     inc    dx
  947.     lodsb
  948.     out    dx,al
  949.     inc    ah
  950.     dec    dx
  951.     loop    parms
  952.     pop    cx
  953.     mov    ax,0b000h
  954.     cld
  955.     mov    es,ax
  956.     xor    di,di
  957.     pop    ax
  958.     rep    stosw
  959. ;
  960.     mov    dx,cntrl
  961.     pop    ax
  962.     add    al,scrn_on
  963.     out    dx,al
  964.     pop    es
  965.     pop    ds
  966.     ret
  967. setmd    endp
  968.  
  969.  
  970.  endif
  971. _TEXT ENDS
  972.  
  973.     END
  974.  
  975.